package com.weiwei.easyapiinterface.controller;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;

import java.net.HttpURLConnection;
import java.net.URL;
import java.util.HashMap;

public class test {
    public static void main(String[] args) throws Exception {
        String url = "https://api.vvhan.com/api/horoscope";
        HashMap<String, Object> paramMap = new HashMap<>();
        paramMap.put("type","aries");
        paramMap.put("time","today");
        paramMap.put("format", "json");
        String result = HttpUtil.get(url, paramMap);
        System.out.println(result);
    }
    
    /**
     * 获取重定向地址
     * @param path
     * @return
     * @throws Exception
     */
    public static String getRedirectUrl(String path) throws Exception {
        //创建HTTP连接对象
        HttpURLConnection conn = (HttpURLConnection) new URL(path)
                .openConnection();
        //设置不跟随重定向,如果为true跟随重定向
        conn.setInstanceFollowRedirects(false);
        conn.setConnectTimeout(5000);
        String location = conn.getHeaderField("Location");
        return location;
    }


}
